/**
 * 针对基础计算 切换CPU测试
 * @file cpuAffinity.c
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2022-04-08
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>


/* Return the UNIX time in microseconds */
long long ustime(void) {
    struct timeval tv;
    long long ust;

    gettimeofday(&tv, NULL);
    ust = ((long long)tv.tv_sec)*1000000;
    ust += tv.tv_usec;
    return ust;
}

void loopfunc(){    
    int c;
    for(int i = 0;i< 999999999; i++){
        c++;
        void * buff = malloc(1024);
        memset(buff, 2, 1024);
        free(buff);
    }
    printf("%d\n", c);
}

int main(int argc, char* argv[]){
    

    int data = 1;
    long long t0, t1;
    char cmd[64] = {0};    

    pid_t pid = getpid();   
    while(1 == 1){
        t0 = ustime();            
        loopfunc();
        t1 = ustime();
        printf("%6f\n", (t1-t0)/1000000.0f);
        fflush(stdout);
        usleep(200);
    }
    return 0;
}